﻿using MyGame.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyGame
{
    public partial class frmMian : Form
    {
        //游戏对象说明
        private Game _game;
        public frmMian()
        {
            InitializeComponent();
        }

        private void frmMian_Load(object sender, EventArgs e)
        {
            //初始化游戏类
            _game = new Game();
        }

        private void gameArea_Paint(object sender, PaintEventArgs e)
        {
            if (_game != null)//游戏已经初始化了
            {
                _game.Draw(e.Graphics, this.gameArea.Size);
            }
        }

        private void gameArea_MouseDown(object sender, MouseEventArgs e)
        {
            if (_game!=null)
            {
                //调用game的鼠标点击处理程序
                Block block=_game.MouseDown(e.Location, this.gameArea.Size);
                //重绘游戏区域
                this.gameArea.Invalidate();
                //处理输赢
                if (block!=null)
                {
                    //点击成功，block就是点击的那个块
                    if (_game.IsGameOver(block))
                    {
                        //游戏结束了
                        MessageBox.Show("Game Over!");
                        _game = new Game();
                    }
                }
            }
        }

        private void btnStartGame_Click(object sender, EventArgs e)
        {
            //重置游戏
            _game = new Game();
            this.gameArea.Invalidate();
        }

        private void btnAboutMy_Click(object sender, EventArgs e)
        {
            //关于我的界面
            FrmAboutme frm = new FrmAboutme();
            frm.ShowDialog();
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            //退出
            this.Close();
        }
    }
}
